﻿using System;
using System.Data;
using System.Web.UI.WebControls;

namespace Fjaspx.UI.Web
{
    /// <summary>
    /// 
    /// </summary>
    public partial class NewList : AdminPage
    {

        private int? _ClassKind = null;
        /// <summary>
        /// 每页分多少 Gets or sets the onepage.
        /// </summary>
        /// <value>The onepage.</value>
        public int? ClassKind 
        {
            get { return _ClassKind; }
            set { _ClassKind = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        Fjaspx.Sys.Bll.ROYcms_class BLL = new Fjaspx.Sys.Bll.ROYcms_class();
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.ClassKind = Convert.ToInt32(Request["ClassKind"]);
                DdlMenu_bind();
                this.DdlMenu.SelectedValue = Request["Id"].ToString();
            }
        }

        #region 数据绑定
        /// <summary>
        /// DDLs the menu_bind.
        /// </summary>
        void DdlMenu_bind()
        {

            DataSet ds = new Fjaspx.Sys.Bll.ROYcms_class().GetClassList(Convert.ToInt32(Request["ClassKind"] == null ? "0" : Request["ClassKind"]));

            this.DdlMenu.Items.Clear();
            this.DdlMenu.Items.Add(new ListItem("生成所有栏目。。。", ""));
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int ClassTj = Convert.ToInt32(dr["ClassTj"]);
                string ClassId = dr["Id"].ToString().Trim();
                string ClassName = dr["ClassName"].ToString().Trim();

                if (ClassTj == 1)
                {
                    this.DdlMenu.Items.Add(new ListItem(ClassName, ClassId));

                }
                else
                {
                    ClassName = "├ " + ClassName;
                    ClassName = Fjaspx.Common.StringPlus.StringOfChar(ClassTj - 1, "　") + ClassName;

                    this.DdlMenu.Items.Add(new System.Web.UI.WebControls.ListItem(ClassName, ClassId));
                }
            }


        }
        #endregion

        /// <summary>
        /// Handles the Click event of the Button_ control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Button__Click(object sender, EventArgs e)
        {
            Fjaspx.Templet.NewIndex NewIndex = new Fjaspx.Templet.NewIndex();
            Fjaspx.Templet.NewList NewList = new Fjaspx.Templet.NewList();
            Fjaspx.Templet.NewShow NewShow = new Fjaspx.Templet.NewShow(); 
            Fjaspx.Sys.Model.ROYcms_class model = BLL.GetModel(Request["ClassId"]);
            try
            {
                if (this.DdlMenu.SelectedValue == "")
                {
                    //生成所有栏目
                   NewList.NewAllHtml(this.ClassKind);
                }
                else 
                { 
                    NewList.classname = Convert.ToInt32(this.DdlMenu.SelectedValue);          
                }
                if (txt_onepage.Text != "")
                {
                    NewList.onepage = Convert.ToInt32(txt_onepage.Text);
                }
                if (NewList.NewHtml(model)) { Response.Write("<center><br><br><br><h3>生成列表成功！</h3></center>"); con.Visible = false; }
                
            }
            catch { Response.Write("<center><h3>生成列表错误！</h3></center>"); con.Visible = false; }
            if (CheckBox_show.Checked)
            {
                try
                {
                    if (txt_sum.Text != "") { NewShow.top = Convert.ToInt32(txt_sum.Text); }
                    if (txt_end_id.Text != "") { NewShow.end_id = Convert.ToInt32(txt_end_id.Text); }
                    if (txt_star_id.Text != "") { NewShow.star_id = Convert.ToInt32(txt_star_id.Text); }
                    if (NewShow.NewHtml(model)) { Response.Write("<center><h3>生成文章成功！</h3></center>"); con.Visible = false; }
                }
                catch { Response.Write("<center><h3>生成文章错误！</h3></center>"); con.Visible = false; }
            }
            if (CheckBox_index.Checked)
            {
                try
                {
                    if (NewIndex.NewHtml()) { Response.Write("<center><h3>生成首页成功！</h3></center>"); con.Visible = false; }
                }
                catch { Response.Write("<center><h3>生成首页错误！</h3></center>"); con.Visible = false; }
            }
        }
    }
}
